package com.jhj.service.bm.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.jhj.po.bm.model.OrderAttr;
import com.jhj.service.bm.OrderAttrService;
import com.jhj.service.impl.BaseServiceImpl;
import com.jhj.utils.TimeStampUtil;

@Service
public class OrderAttrServiceImpl extends BaseServiceImpl<OrderAttr> implements OrderAttrService {

	@Override
	public List<OrderAttr> select(OrderAttr attr) {
		return mapper.select(attr);
	}

	@Override
	public OrderAttr setOrderAttr(Integer orderId, String orderNo, Integer serviceTypeId, String attrType, String attrName, String attrValue, Integer attrId) {
		
		OrderAttr searchVo = new OrderAttr();
		searchVo.setOrderId(orderId);
		searchVo.setServiceTypeId(serviceTypeId);
		searchVo.setAttrType(attrType);
		OrderAttr record = this.selectOne(searchVo);
		if (record == null) record = this.initPo(new OrderAttr());
		record.setOrderId(orderId);
		record.setOrderNo(orderNo);
		record.setServiceTypeId(serviceTypeId);
		record.setAttrName(attrName);
		record.setAttrType(attrType);
		record.setAttrValue(attrValue);
		record.setAttrId(attrId);
		
		if (record.getId() > 0) {
			this.update(record);
		} else {
			record.setAddTime(TimeStampUtil.getNowSecond().intValue());
			this.insert(record);
		}
		
		return record;
	}
	
}
